package com.example.meitu.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.meitu.api.domain.MediaRecommand;
import com.example.meitu.api.dto.RecommandMediaForm;
import com.example.meitu.api.service.MediaRecommandService;
import com.example.meitu.api.dao.MediaRecommandMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 蔡超
* @description 针对表【mt_media_recommand(媒体推荐表)】的数据库操作Service实现
* @createDate 2024-06-28 16:05:44
*/
@Service
public class MediaRecommandServiceImpl extends ServiceImpl<MediaRecommandMapper, MediaRecommand>
    implements MediaRecommandService{

    @Resource
    private MediaRecommandMapper mediaRecommandMapper;

    /**
     *
     * @param recommandMediaForm
     * @return
     */
    @Override
    public List<MediaRecommand> recommandMedia(RecommandMediaForm recommandMediaForm) {
        LambdaQueryWrapper<MediaRecommand> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(MediaRecommand::getDelFlag, '0');
        lambdaQueryWrapper.eq(MediaRecommand::getBrandId, recommandMediaForm.getBrandId());
        if (StringUtils.isNotBlank(recommandMediaForm.getPlatform())) {
            lambdaQueryWrapper.eq(MediaRecommand::getPlatform, recommandMediaForm.getPlatform());
        }
        if (StringUtils.isNotBlank(recommandMediaForm.getMeitidalei())) {
            lambdaQueryWrapper.eq(MediaRecommand::getMeitidalei, recommandMediaForm.getMeitidalei());
        }
        if (StringUtils.isNotBlank(recommandMediaForm.getHangyexifen())) {
            lambdaQueryWrapper.eq(MediaRecommand::getHangyexifen, recommandMediaForm.getHangyexifen());
        }
        if (StringUtils.isNotBlank(recommandMediaForm.getXifenquanceng())) {
            lambdaQueryWrapper.eq(MediaRecommand::getXifenquanceng, recommandMediaForm.getXifenquanceng());
        }
        if (recommandMediaForm.getType() == 1) {
            lambdaQueryWrapper.orderByDesc(MediaRecommand::getRecommandScore);
        }
        if (recommandMediaForm.getType() == 0) {
            lambdaQueryWrapper.orderByDesc(MediaRecommand::getUnrecommandScore);
        }
        String lastSql = " limit " + recommandMediaForm.getNum();
        lambdaQueryWrapper.last( lastSql);
        return list(lambdaQueryWrapper);
    }

    @Override
    public List<MediaRecommand> recommandMedia2(RecommandMediaForm recommandMediaForm) {
        return mediaRecommandMapper.recommandMedia2(recommandMediaForm);
    }
}




